package com.ktgj.hotel.controller;

import java.util.List;
import java.io.IOException;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.ktgj.common.core.domain.R;
import com.ktgj.hotel.domain.HotelRoomPrice;
import com.ktgj.hotel.domain.common.HotelInfo;
import com.ktgj.hotel.domain.common.Hotels;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ktgj.common.log.annotation.Log;
import com.ktgj.common.log.enums.BusinessType;
import com.ktgj.common.security.annotation.PreAuthorize;
import com.ktgj.hotel.domain.HotelRoom;
import com.ktgj.hotel.service.IHotelRoomService;
import com.ktgj.common.core.web.controller.BaseController;
import com.ktgj.common.core.web.domain.AjaxResult;
import com.ktgj.common.core.utils.poi.ExcelUtil;
import com.ktgj.common.core.web.page.TableDataInfo;

/**
 * 酒店房型信息Controller
 * 
 * @author ruoyi
 * @date 2022-08-25
 */
@RestController
@RequestMapping("/HotelRoom")
public class HotelRoomController extends BaseController
{
    @Autowired
    private IHotelRoomService hotelRoomService;

    /**
     * 查询酒店房型信息列表
     */
    @PreAuthorize(hasPermi = "system:room:list")
    @GetMapping("/list")
    public TableDataInfo list(HotelRoom hotelRoom)
    {
        startPage();
        List<HotelRoom> list = hotelRoomService.selectHotelRoomList(hotelRoom);
        return getDataTable(list);
    }

    /**
     * 导出酒店房型信息列表
     */
    @PreAuthorize(hasPermi = "system:room:export")
    @Log(title = "酒店房型信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, HotelRoom hotelRoom) throws IOException
    {
        List<HotelRoom> list = hotelRoomService.selectHotelRoomList(hotelRoom);
        ExcelUtil<HotelRoom> util = new ExcelUtil<HotelRoom>(HotelRoom.class);
        util.exportExcel(response, list, "酒店房型信息数据");
    }

    /**
     * 获取酒店房型信息详细信息
     */
    @PreAuthorize(hasPermi = "system:room:query")
    @GetMapping(value = "/{roomId}")
    public AjaxResult getInfo(@PathVariable("roomId") Long roomId)
    {
        return AjaxResult.success(hotelRoomService.selectHotelRoomById(roomId));
    }

    /**
     * 新增酒店房型信息
     */
    @PreAuthorize(hasPermi = "system:room:add")
    @Log(title = "酒店房型信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HotelRoom hotelRoom)
    {
        return toAjax(hotelRoomService.insertHotelRoom(hotelRoom));
    }

    /**
     * 修改酒店房型信息
     */
    @PreAuthorize(hasPermi = "system:room:edit")
    @Log(title = "酒店房型信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HotelRoom hotelRoom)
    {
        return toAjax(hotelRoomService.updateHotelRoom(hotelRoom));
    }

    /**
     * 删除酒店房型信息
     */
    @PreAuthorize(hasPermi = "system:room:remove")
    @Log(title = "酒店房型信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{roomIds}")
    public AjaxResult remove(@PathVariable Long[] roomIds)
    {
        return toAjax(hotelRoomService.deleteHotelRoomByIds(roomIds));
    }

    /**
     * 新增酒店信息
     * */
    @PostMapping("/insertHotel")
    public AjaxResult insertHotel(HttpServletRequest request, @RequestBody Hotels hotels){
        int i;
        try {
            i = hotelRoomService.insertHotel(request, hotels);
        } catch (Exception e){
            return AjaxResult.error(e.getMessage());
        }

        if (i > 0){
            return AjaxResult.success("添加成功");
        }
        else {
            return AjaxResult.error("添加失败");
        }
    }

    /**
     * 查询待修改的酒店信息
     * */
    @PostMapping("/hotelDetails")
    public AjaxResult hotelDetails(@RequestBody Map<String, Object> map){
        String type = map.get("type").toString();
        Long id = Long.valueOf(map.get("id").toString());
        Hotels hotels = hotelRoomService.hotelDetails(type, id);

        return AjaxResult.success(hotels);
    }

    /**
     * 修改酒店信息
     * */
    @PostMapping("/updateHotel")
    public AjaxResult updateHotel(@RequestBody Hotels hotels){
        int i;
        try {
            i = hotelRoomService.updateHotel(hotels);
        } catch (Exception e){
            return AjaxResult.error(e.getMessage());
        }

        if (i > 0){
            return AjaxResult.success("修改成功");
        }
        else {
            return AjaxResult.error("修改失败");
        }
    }

    /**
     * 酒店详情
     * */
    @PostMapping("/hotelInfoDetails")
    public AjaxResult hotelInfoDetails(@RequestBody Map<String, Object> map){
        Long id = Long.valueOf(map.get("id").toString());

        HotelInfo hotelInfo = hotelRoomService.hotelInfoDetails(id);
        return AjaxResult.success(hotelInfo);
    }

    /**
     * 酒店房型列表
     * */
    @PostMapping("/selHotelRoom")
    public AjaxResult selHotelRoom(@RequestBody Map<String, Object> map){
        Long id = Long.valueOf(map.get("id").toString());
        List<HotelRoom> hotelRoomList = hotelRoomService.selHotelRoom(id);
        return AjaxResult.success(hotelRoomList);
    }

    /**
     * 酒店房型价格列表
     * */
    @PostMapping("/roomPrice")
    public AjaxResult roomPrice(@RequestBody Map<String, Object> map){
        Long id = Long.valueOf(map.get("id").toString());
        List<HotelRoomPrice> hotelRoomPriceList = hotelRoomService.roomPrice(id);
        return AjaxResult.success(hotelRoomPriceList);
    }
}
